package org.jeecg.modules.jd.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.pdd.util.DingDanXiaUtil;

import java.util.HashMap;
import java.util.Map;

public class JDPositionUtil {


    /**
     * 创建推广位
     *
     * @param spaceNameList
     * @return
     */
    public static String createPosition(String spaceNameList) {

        String url = "http://api.tbk.dingdanxia.com/jd/create_position";
        Map<String, Object> map = new HashMap<>();
        map.put("apikey", DingDanXiaUtil.dingdanxia_appkey);
        map.put("unionId", JDContants.unionId);
        map.put("key", JDContants.key);
        map.put("unionType", JDContants.unionType);
        map.put("type", JDContants.type);
        map.put("spaceNameList", spaceNameList);
        map.put("siteId", JDContants.appId);

        String resultStr = null;
        try {
            resultStr = HttpUtil.post(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultStr;

    }

    /**
     * 获取推广位
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public static String getPosition(Integer pageIndex, Integer pageSize) {

        String url = "http://api.tbk.dingdanxia.com/jd/query_position";
        Map<String, Object> map = new HashMap<>();
        map.put("apikey", DingDanXiaUtil.dingdanxia_appkey);
        map.put("unionId", JDContants.unionId);
        map.put("key", JDContants.key);
        map.put("unionType", "3");
        map.put("pageIndex", pageIndex);
        map.put("pageSize", pageSize);

        String resultStr = "";
        try {
            resultStr = HttpUtil.post(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resultStr;
    }


}
